package chances.declare.repo;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import chances.declare.entity.CPContent;
import chances.declare.entity.CPContentAndOplog;
import chances.declare.web.CPcontentQueryModel;
import chances.system.operator.entity.EnumData;

/**
* @Author WangCC
* @Date 2017年7月28日 下午1:55:08
* chances.declare.repo
* @Version 1.0
* 内容申报
*/
public interface CPContentRepository extends JpaRepository<CPContent, Long> {

    @Query("select c from CPContent c")
    public Page<CPContent> findCPContentByOrgId(CPcontentQueryModel queryModel, Pageable pageable);

    @Query("select e from EnumData e where parentId=:parentId And value=:value")
    EnumData findByValue(@Param("parentId") Long parentId, @Param("value") String value);

    @Query("select c from CPContent c where status != -1 And code=:code")
    List<CPContent> findByCode(@Param("code") String code);

    @Query("select c from CPContent c where status != -1 And code=:code And id !=:id")
    List<CPContent> findByCodes(@Param("code") String code, @Param("id") Long id);

    @Query("select c from CPContent c where status != -1 And externalCode=:externalCode")
    List<CPContent> findByExternalCode(@Param("externalCode") String externalCode);

    @Query("select c from CPContent c where status != -1 And externalCode=:externalCode And id !=:id")
    List<CPContent> findByExternalCodes(@Param("externalCode") String externalCode,
            @Param("id") Long id);

    @Query("from CPContent")
    public Page<CPContentAndOplog> search(@Param("id") Long id, @Param("name") String name,
            @Param("operateType") String operateType, @Param("orgName") String orgName,
            @Param("opName") String opName, @Param("beginTime") String beginTime,
            @Param("endTime") String endTime, Pageable pageable);
    
    @Query("select c from CPContent c where c.unitContentId = :unitContentId")
	List<CPContent> searchCPContent(@Param("unitContentId")Long unitContentId);
}
